<script>
    function deepCopy(data, cache = new Map()) {
      if (typeof data !== 'object') {
        return data
      }
      if(cache.has(data)){
        return cache.get(data)
      }
      let result = Array.isArray(data) ? [] : {}
      cache.set(data, result)
      if (Array.isArray(result)) {
        for (let i = 0; i < data.length; i++) {
          result.push(deepCopy(data[i] ,cache))
        }
      } else {
        for (let key in data) {
          result[key] = deepCopy(data[key], cache)
        }
      }
      return result
    }

    let arr = [1, 2, { name: '长江' }]
    arr[0] = arr
    let newArr = deepCopy(arr)
    console.log(newArr)
  </script>
  